<%var body = {%>

<blockquote class="layui-elem-quote">
新增导入：如果导入的Excel表格中没有主键列，则自动新增所有行的数据。<br />
更新导入：如果导入的Excel表格中存在主键列，则自动根据每行主键更新相关数据。<br />
</blockquote>

<div style="padding: 5px;">
<form target="ajaxUpload" id="importForm" action="/single_grid/doImportXls/${menuCode}" method="POST" enctype="multipart/form-data">
	<input type="file" id="upfile" name="upfile" value="上传" formaction="importForm" placeholder="请选择要上传的xls文件" accept=".xls" style="height: 100%">
</form>
</div>

<iframe name="ajaxUpload" style="display:none">
</iframe>
<script type="text/javascript">

	var extArray = new Array(".xls");

	function limit(file){
	    var allowSubmit = false;
	    if (!file){
	    	$.msg('请选择一个Excel文件!', $ppjq);
	        return false;
	    }
	    while (file.indexOf("\\") != -1){
	        file = file.slice(file.indexOf("\\") + 1);
	    }
	    var ext = file.slice(file.lastIndexOf(".")).toLowerCase();
	    for (var i = 0; i < extArray.length; i++) {
	        if (extArray[i] == ext){
	            allowSubmit = true;
	            break;
	        }
	    }
	    if (!allowSubmit){
	    	alert("只能上传以下格式的文件:"+ (extArray.join("")) + "\n请重新选择再上传.");
	    	return false;
	    }
	    return true;
	}
</script>


<script type="text/javascript">
// ------------------------- 动态参数配置
var $form = $('#importForm');
var action = '/button/doQuick';
var msg = '添加按钮成功';

var $pjq;
var PID;
// ------------------------- 动态参数配置

// 确认按钮回调
var btnSaveCallback = function($dialog, ID, $$) {
	$pjq = $$;
	PID = ID;
	
	var $file = $('#upfile');
	if (limit($file.val())) {
		$form.submit();
	}
};

//上传回调:IFrame Ajax上传
var callback = function (msg, success){
	if (success) {
		$pjq.msg(msg);
	} else {
		$pjq.error(msg);
	}
	$.parentTableReLoad(PID);
	$.dialogClose(parent.layer, window);
}
</script>

<%};include("/eova/layout/form.html",{'title' : '导入数据', 'layoutContent' : body, 'isEditor' : false}){}%>